from flask import Flask, render_template
from flask_migrate import Migrate
from models import File, Lock
from exts import db
import config

from blueprints.file import bp as file_bp
from blueprints.lock import bp as lock_bp

app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)

app.register_blueprint(file_bp)
app.register_blueprint(lock_bp)

migrate = Migrate(app, db)


@app.route('/')
def hello_world():  # put application's code here
    return render_template("/index.html")


@app.route("/download")
def download():
    if db.session.query(Lock).first().open == 1:
        return render_template("lock.html")

    content = {
        "files": db.session.query(File).all()
    }
    return render_template("download.html", **content)


@app.route("/upload")
def upload():
    return render_template("upload.html")


if __name__ == '__main__':
    app.run(
        host='0.0.0.0',
        port=6000
    )
